import 'package:flutter/material.dart';
import 'package:get/get.dart';

class GetxUiDemoPage extends StatelessWidget {
  const GetxUiDemoPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('GetX UI/Utils 示例'),
        leading: IconButton(
          icon: const Icon(Icons.home),
          onPressed: () => Get.offAllNamed('/'),
        ),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            ElevatedButton(
              onPressed: () => Get.snackbar('提示', '这是一个 Get.snackbar 示例'),
              child: const Text('展示 Snackbar'),
            ),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: () {
                Get.dialog(
                  AlertDialog(
                    title: const Center(child: Text('确认操作')),
                    content: const Text('你确定要执行此操作吗？'),
                    actionsAlignment: MainAxisAlignment.spaceBetween,
                    actions: [
                      TextButton(
                        onPressed: () => Get.back(result: false),
                        child: const Text('取消'),
                      ),
                      TextButton(
                        onPressed: () => Get.back(result: true),
                        child: const Text('确认'),
                      ),
                    ],
                  ),
                ).then((value) {
                  if (value == true) {
                    Get.snackbar('结果', '你点击了确认');
                  } else {
                    Get.snackbar('结果', '你点击了取消');
                  }
                });
              },
              child: const Text('展示 Dialog 确认/取消'),
            ),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: () {
                Get.bottomSheet(
                  Container(
                    color: Colors.white,
                    padding: const EdgeInsets.all(24),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        const Text('这是一个 BottomSheet'),
                        const SizedBox(height: 16),
                        ElevatedButton(
                          onPressed: () => Get.back(),
                          child: const Text('关闭'),
                        ),
                      ],
                    ),
                  ),
                );
              },
              child: const Text('展示 BottomSheet'),
            ),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: () {
                const email = 'test@example.com';
                const phone = '13800138000';
                const url = 'https://flutter.dev';
                final isEmail = GetUtils.isEmail(email);
                final isPhone = GetUtils.isPhoneNumber(phone);
                final isUrl = GetUtils.isURL(url);
                Get.snackbar(
                  'GetUtils 检查',
                  'isEmail: $isEmail\nisPhone: $isPhone\nisUrl: $isUrl',
                  duration: const Duration(seconds: 3),
                );
              },
              child: const Text('GetUtils 常用方法'),
            ),
          ],
        ),
      ),
    );
  }
}
